home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Sleep Deprivation 1.1 / source / sd code ƒ / ◊ sd main.c < prev    next >
Encoding:
Text File  |  1994-10-30  |  6.2 KB  |  172 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        sd main.c
  4.  
  5. Purpose:    This module handles the sleep proc dispatch, doing the
  6.             Right Thing™ on sleep request, demand, and wake up.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "sd main.h"
  26. #include "sd init.h"
  27. #include "globals.h"
  28. #include "fade headers.h"
  29. #include "reversed fade headers.h"
  30.  
  31. #define NUM_WIPES 50
  32.  
  33. void sdMain(void)
  34. {
  35.     // sorry about the assembly, but the codes are passed to the sleep proc in
  36.     // register d0, which is tough to check from C.
  37.     
  38.     asm
  39.     {
  40.         cmpi.l    #sleepRequest, d0
  41.         bne        @1
  42.         clr.l    d0
  43.         bra        @4
  44.     @1    cmpi.l    #sleepWakeUp, d0
  45.         bne        @2
  46.         movem.l    a0-a5/d0-d7, -(sp)
  47.     }
  48.     
  49.     // the system will not automatically redraw the screen; since we've blacked
  50.     // it out, we need to manually redraw it when the computer wakes up.
  51.     
  52.     DrawMenuBar();
  53.     PaintOne(0L,GrayRgn);
  54.     PaintBehind(WindowList,GrayRgn);
  55.     
  56.     asm
  57.     {
  58.         bra        @3
  59.     @2    cmpi.l    #sleepDemand, d0
  60.         bne        @4
  61.         movem.l    a0-a5/d0-d7, -(sp)
  62.     }
  63.     
  64.     sdDispatch((Ticks&0x7fffffff)%NUM_WIPES);
  65.     
  66.     asm
  67.     {
  68.     @3    movem.l    (sp)+, a0-a5/d0-d7
  69.     @4
  70.     }
  71. }
  72.  
  73. void sdDispatch(int whichWipe)
  74. {
  75.     int                oldMenuBarHeight;
  76.     long            oldA5;
  77.     QDGlobals        qd;                /* our QD globals. */
  78.     GrafPort        gp;                /* our grafport. */
  79.     GrafPtr            savePort;
  80.     THz                saveZone;
  81.     GrafPtr            thePort;
  82.     
  83.     SetUpA4();
  84.     
  85.     GetPort(&savePort);
  86.     oldMenuBarHeight=MBarHeight;
  87.     MBarHeight=0;
  88.     DrawMenuBar();
  89.  
  90.     /* get a value for A5, a structure that mirrors qd globals. */
  91.     oldA5 = SetA5((long)&qd.end);
  92.     InitGraf(&qd.thePort);
  93.     OpenPort(&gp);
  94.     thePort=&gp;
  95.     SetPort(thePort);
  96.     
  97.     HideCursor();
  98.     
  99.     saveZone=GetZone();
  100.     SetZone(SysZone);
  101.  
  102.     if (whichWipe==0)        BoxInFade(gp.portRect, &qd.black);
  103.     else if (whichWipe==1)    BoxOutFade(gp.portRect, &qd.black);
  104.     else if (whichWipe==2)    CircleBulgeFade(gp.portRect, &qd.black);
  105.     else if (whichWipe==3)    CircleInFade(gp.portRect, &qd.black);
  106.     else if (whichWipe==4)    CircleOutFade(gp.portRect, &qd.black);
  107.     else if (whichWipe==5)    CircleSerendipityFade(gp.portRect, &qd.black);
  108.     else if (whichWipe==6)    CircularFade(gp.portRect, &qd.black);
  109.     else if (whichWipe==7)    DiagonalFade(gp.portRect, &qd.black);
  110.     else if (whichWipe==8)    FourCornerFade(gp.portRect, &qd.black);
  111.     else if (whichWipe==9)    FullScrollLRFade(gp.portRect, &qd.black);
  112.     else if (whichWipe==10)    FullScrollUDFade(gp.portRect, &qd.black);
  113.     else if (whichWipe==11)    HalvesScrollFade(gp.portRect, &qd.black);
  114.     else if (whichWipe==12) HilbertFade(gp.portRect, &qd.black);
  115.     else if (whichWipe==13)    MrDoOutdoneFade(gp.portRect, &qd.black);
  116.     else if (whichWipe==14)    MrDoFade(gp.portRect, &qd.black);
  117.     else if (whichWipe==15)    PourScrollFade(gp.portRect, &qd.black);
  118.     else if (whichWipe==16)    RandomFade(gp.portRect, &qd.black);
  119.     else if (whichWipe==17)    RescueRaidersFade(gp.portRect, &qd.black);
  120.     else if (whichWipe==18)    SkipalineLRFade(gp.portRect, &qd.black);
  121.     else if (whichWipe==19)    SkipalineFade(gp.portRect, &qd.black);
  122.     else if (whichWipe==20)    SpiralGyraFade(gp.portRect, &qd.black);
  123.     else if (whichWipe==21)    CircularFadeReversed(gp.portRect, &qd.black);
  124.     else if (whichWipe==22)    DiagonalFadeDownRight(gp.portRect, &qd.black);
  125.     else if (whichWipe==23)    FourCornerFadeReversed(gp.portRect, &qd.black);
  126.     else if (whichWipe==24)    FullScrollLeftFade(gp.portRect, &qd.black);
  127.     else if (whichWipe==25)    FullScrollUpFade(gp.portRect, &qd.black);
  128.     else if (whichWipe==26)    HalvesScrollFadeReversed(gp.portRect, &qd.black);
  129.     else if (whichWipe==27)    HilbertFadeReversed(gp.portRect, &qd.black);
  130.     else if (whichWipe==28)    MrDoOutdoneFadeReversed(gp.portRect, &qd.black);
  131.     else if (whichWipe==29)    MrDoFadeReversed(gp.portRect, &qd.black);
  132.     else if (whichWipe==30)    PourScrollFadeReversed(gp.portRect, &qd.black);
  133.     else if (whichWipe==31)    RescueRaidersFadeReversed(gp.portRect, &qd.black);
  134.     else if (whichWipe==32)    HGRFade(gp.portRect, &qd.black);
  135.     else if (whichWipe==33)    HGR2Fade(gp.portRect, &qd.black);
  136.     else if (whichWipe==34)    QuadrantFade2(gp.portRect, &qd.black);
  137.     else if (whichWipe==35)    QuadrantFade(gp.portRect, &qd.black);
  138.     else if (whichWipe==36)    QuadrantScroll2Fade(gp.portRect, &qd.black);
  139.     else if (whichWipe==37)    QuadrantScrollFade(gp.portRect, &qd.black);
  140.     else if (whichWipe==38)    SkipalineLR2PassFade(gp.portRect, &qd.black);
  141.     else if (whichWipe==39)    Skipaline2PassFade(gp.portRect, &qd.black);
  142.     else if (whichWipe==40)    HGRFadeReversed(gp.portRect, &qd.black);
  143.     else if (whichWipe==41)    HGR2FadeReversed(gp.portRect, &qd.black);
  144.     else if (whichWipe==42)    QuadrantFade2Reversed(gp.portRect, &qd.black);
  145.     else if (whichWipe==43)    QuadrantFadeReversed(gp.portRect, &qd.black);
  146.     else if (whichWipe==44)    QuadrantScroll2FadeReversed(gp.portRect, &qd.black);
  147.     else if (whichWipe==45)    QuadrantScrollFadeReversed(gp.portRect, &qd.black);
  148.     else if (whichWipe==46)    SkipalineLR2PassFadeReversed(gp.portRect, &qd.black);
  149.     else if (whichWipe==47)    Skipaline2PassFadeReversed(gp.portRect, &qd.black);
  150.     else if (whichWipe==48) SlideFade(gp.portRect, &qd.black);
  151.     else if (whichWipe==49) SlideFadeReversed(gp.portRect, &qd.black);
  152.     
  153. // You would think a simple switch-case statement would suffice, but you would
  154. // be mistaken.  In fact, the following switch-case causes a crash on a Powerbook
  155. // 100.  This is most likely a THINK C bug; it is super-optimizing the switch-case
  156. // so much that it no longer works on a 68000 machine.  The series of if-then-elses
  157. // is less elegant to the programmer, but more elegant to the user, since it
  158. // doesn't crash.  (:
  159.  
  160.     SetZone(saveZone);
  161.     
  162.     MBarHeight=oldMenuBarHeight;
  163.     ShowCursor();
  164.     ObscureCursor();
  165.     
  166.     ClosePort(&gp);
  167.     SetA5(oldA5);
  168.     SetPort(savePort);
  169.     
  170.     RestoreA4();
  171. }
  172.